package com.scopionstudio.adapter;

import java.util.List;

import com.scopionstudio.bean.ItemsMusic;
import com.scopionstudio.djnonstop.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AdapterListMain extends ArrayAdapter<ItemsMusic>{
	private LayoutInflater mInflater;
	public AdapterListMain(Context context, int textViewResourceId,
			List<ItemsMusic> objects) {
		super(context, textViewResourceId, objects);
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mHolder;
		ItemsMusic mItemsMusic = this.getItem(position);
		if(convertView == null){
			mHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_list_song, null);
			mHolder.mNameSongs = (TextView) convertView.findViewById(R.id.tv_name_songs);
			mHolder.mHearing = (TextView) convertView.findViewById(R.id.tv_hearing);
			convertView.setTag(mHolder);
		}else{
			mHolder = (ViewHolder) convertView.getTag();
		}
		if(mItemsMusic.getName() != null ){
			mHolder.mNameSongs.setText(mItemsMusic.getName().substring(0, 28)+"...");
		}else{
			mHolder.mNameSongs.setText("DJ Music 2013");
		}
			
		mHolder.mHearing.setText("Lượt nghe : " + mItemsMusic.getHearing());
		return convertView;
	}
	class ViewHolder{
		TextView mNameSongs,mHearing;
	}

}
